package com.xinsilu.hospital.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.xinsilu.hospital.entity.AuthsysPermission;
import com.xinsilu.hospital.entity.AuthsysResources;
import com.xinsilu.hospital.mapper.AuthsysOperatorMapper;
import com.xinsilu.hospital.mapper.AuthsysPermissionMapper;

import com.xinsilu.hospital.mapper.AuthsysResourcesMapper;
import com.xinsilu.hospital.service.IAuthsysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ym
 * @since 2021-11-30
 */
@Service
public class AuthsysPermissionServiceImpl extends ServiceImpl<AuthsysPermissionMapper, AuthsysPermission> implements IAuthsysPermissionService {
    @Autowired
    private AuthsysPermissionMapper permissionMapper;
    @Autowired
    private AuthsysResourcesMapper resourcesMapper;
    @Autowired
    private AuthsysOperatorMapper operatorMapper;

    @Override
    public List<AuthsysPermission> searchPermissions() {
        List<AuthsysPermission> permissionList =  this.permissionMapper.selectAllSimplePermissions();
        if(permissionList != null){
            for(AuthsysPermission permission:permissionList){
                permission.setResources(this.resourcesMapper.selectByPrimaryKey(permission.getRscId()));
                permission.setOperator(this.operatorMapper.selectByPrimaryKey(permission.getOptId()));
            }
        }
        return permissionList;
    }

    @Override
    public List<AuthsysPermission> searchUserPermissions(String userName) {
        return this.permissionMapper.selectByUserName(userName);
    }
}
